package ch.mobi.osgi2maven2.pom;

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;

import org.apache.velocity.VelocityContext;
import org.apache.velocity.app.Velocity;
import org.apache.velocity.context.Context;


public class PomGenerator {
	
	private static final String CONTEXT_NAME = "pom";
	private static final String TEMPLATE_NAME="pom.vm";
	
	public static void generatePom(File file, PomFile data) throws IOException {
		Context ctx=new VelocityContext();
		ctx.put(CONTEXT_NAME, data);
		FileWriter writer=new FileWriter(file);
		InputStream is=Thread.currentThread().getContextClassLoader().getResourceAsStream(TEMPLATE_NAME);
		Velocity.evaluate(ctx, writer, TEMPLATE_NAME, new InputStreamReader(is));
		writer.close();
		is.close();
	}

}
